package com.lorry;

import java.util.LinkedList;
import java.util.Queue;

public class ThreadCommunication {


    public static void main(String[] args) {
        Queue<Integer> queue = new LinkedList();
        int Max_size = 1;
        synchronized (queue){
            while (queue.size()==Max_size){
                try {
                    queue.wait();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

            queue.add(10);
//            queue.notifyAll();
        }

        //消费者线程
        synchronized (queue){
            while (queue.size()==0){
                try {
                    queue.wait();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

            queue.poll();
            queue.notifyAll();
        }

    }
}
